package mya_dc.shared_classes.gui;

import java.awt.datatransfer.*;
import java.awt.*;

/**
 * A class that allows copying to clipboard
 *
 * @author      Internet
 */
public class Java2Clipboard implements ClipboardOwner
{
    public void toClipboard(String message) {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null) {
        try {
           sm.checkSystemClipboardAccess();
           }
        catch (Exception e) {e.printStackTrace();}
        }
      Toolkit tk = Toolkit.getDefaultToolkit();
      StringSelection st = 
           new StringSelection(message);
      Clipboard cp = tk.getSystemClipboard();
      cp.setContents(st, this);
    }

    public void lostOwnership(Clipboard clip, Transferable tr) { 
       //System.out.println("Lost Clipboard Ownership?!?");
    }
    public static void copyToClipboard(String message)
    {
    	Java2Clipboard tmp = new Java2Clipboard();
    	tmp.toClipboard(message);
    }
}
